package com.vickw.websocketdemo.config;

import com.vickw.websocketdemo.handler.MyWebSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @version 1.0
 * @Description：
 * @Author VickW
 * @Date 2025/3/3 21:26
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册WebSocket处理器，指定WebSocket路径为 "/ws"
        registry.addHandler(new MyWebSocketHandler(), "/ws").setAllowedOrigins("*"); // 允许所有来源
    }
}
